package com.li.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.li.mapper.SysOperLogMapper;
import com.li.service.OperLogService;

import com.li.system.SysOperLog;
import com.li.vo.SysOperLogQueryVo;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class SysOperLogServiceImpl extends ServiceImpl<SysOperLogMapper, SysOperLog>  implements OperLogService {

    @Autowired
    private SysOperLogMapper sysOperLogMapper;

    @Override
    public void saveSysLog(SysOperLog sysOperLog) {
        sysOperLogMapper.insert(sysOperLog);
    }

    //操作日志分页查询
    @Override
    public IPage<SysOperLog> selectPage(Long page, Long limit, SysOperLogQueryVo sysOperLogQueryVo) {
        Page<SysOperLog> operLogPage = new Page<>(page,limit);

        LambdaQueryWrapper<SysOperLog> wrapper = new LambdaQueryWrapper<>();
        if (!StringUtils.isEmpty(sysOperLogQueryVo.getTitle())){
            wrapper.like(SysOperLog::getTitle,sysOperLogQueryVo.getTitle());
        }
        if (!StringUtils.isEmpty(sysOperLogQueryVo.getOperName())){
            wrapper.like(SysOperLog::getOperName,sysOperLogQueryVo.getOperName());
        }
        if (!StringUtils.isEmpty(sysOperLogQueryVo.getCreateTimeBegin())){
            wrapper.ge(SysOperLog::getCreateTime,sysOperLogQueryVo.getCreateTimeBegin());
        }
        if (!StringUtils.isEmpty(sysOperLogQueryVo.getCreateTimeEnd())){
            wrapper.le(SysOperLog::getCreateTime,sysOperLogQueryVo.getCreateTimeEnd());
        }

        IPage<SysOperLog> sysOperLogPage = sysOperLogMapper.selectPage(operLogPage, wrapper);

        return sysOperLogPage;
    }
}
